package cn.com.hatech.blog.module.admin.category.controller;

import cn.com.hatech.blog.common.constant.Types;
import cn.com.hatech.blog.common.controller.BaseController;
import cn.com.hatech.blog.common.exception.TipException;
import cn.com.hatech.blog.common.result.RestResponse;
import cn.com.hatech.blog.module.admin.category.service.IMetaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: hatech-blog
 * @package: cn.com.hatech.blog.module.admin.controller
 * @className: CategoryController
 * @author: xuruikai
 * @description: 分类管理控制器
 * @date: 2020/1/11 14:27
 * @version: 1.0
 */
@RestController
@RequestMapping("/api/v1/admin/category")
@Slf4j
public class CategoryRestController extends BaseController {

    /**
     * 分类管理业务层接口注入
     */
    @Autowired
    private IMetaService metaService;

    @PostMapping(value = "/save")
    @ResponseBody
    @Transactional(rollbackFor = TipException.class)
    public RestResponse saveCategory(@RequestParam String cname, @RequestParam String id) {
        metaService.saveMeta(Types.CATEGORY.getType(), cname, id);
        return RestResponse.ok();
    }

    /**
     * 删除分类
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public RestResponse delete(@RequestParam String id) {
        metaService.delete(id);
        return RestResponse.ok();
    }

}
